package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.AnnouncementMapper;
import com.tanhua.model.domain.Announcement;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class AnnouncementApiImpl implements AnnouncementApi {

    @Autowired
    private AnnouncementMapper announcementMapper;

    /**
     * 分页查询出所有公告
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public List<Announcement> findAnnouncementsList(Integer page, Integer pagesize) {
        Page pages = new Page(page, pagesize);
        LambdaQueryWrapper<Announcement> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(Announcement::getCreated);
        pages = announcementMapper.selectPage(pages, lqw);
        return pages.getRecords();
    }
}
